package com.ledim.utils;

import android.text.TextUtils;
import com.ledim.environment.CommonDefind;

/**
 * Created by qjq on 16/8/25.
 * SharedPreferences工具类
 */
public class LedimSpUtils {

    public static final String USERINFO = "user_info";
    public static final String IS_LOGIN = "isLogin";
    public static final String USER = "user";
    public static final String UID = "uid";
    public static final String TOKEN = "token";
    public static final String LETVID = "letv_id";
    public static final String LOCATION_LATITUDE = "LOCATION_LATITUDE";
    public static final String LOCATION_LONGITUDE = "LOCATION_LONGITUDE";
    public static final String HOME_LOCAL_DATA = "home_local_data";
    public static final String IS_FIRST_SHOW_DIALOG = "IS_FIRST_SHOW_DIALOG";
    public static final String SERVER_DEBUG_MARK = "server_debug_mark";
    public static final String LAUNCH_IMAGE_URL = "launch_image_url";
    public static final String PUSH_MSG_COUNT = "push_msg_count";
    public static final String PUSH_MSG_ID = "push_msg_id";
    public static final String DEVICE_ID = "device_id";
    public static final String PUSH_MSG = "push_msg";


    /**
     * 判断是否是本人
     *
     * @return
     */
    public static boolean isMe(String uid) {
        if (!TextUtils.isEmpty(LedimSpUtils.getUid()) && !TextUtils.isEmpty(uid)) {
            if (LedimSpUtils.getUid().equals(uid)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 设置push消息标记
     *
     * @param value
     */
    public static void setPushMsg(boolean value) {
        LedimBaseSpUtils.put(PUSH_MSG, value, USERINFO);
    }

    /**
     * 获取push消息标记
     *
     * @return
     */
    public static boolean getPushMsg() {
        return (Boolean) LedimBaseSpUtils.get(PUSH_MSG, true, USERINFO);
    }
    

    /**
     * 设置启动图片的url
     *
     * @param url
     */
    public static void setLaunchImageUrl(String url) {
        LedimBaseSpUtils.put(LAUNCH_IMAGE_URL, url, USERINFO);
    }

    /**
     * 获取启动图片的url
     *
     * @return
     */
    public static String getLaunchImageUrl() {
        return (String) LedimBaseSpUtils.get(LAUNCH_IMAGE_URL, "", USERINFO);
    }

    /**
     * 设置UID
     *
     * @param value
     */
    public static void setUid(String value) {
        LedimBaseSpUtils.put(UID, value, USERINFO);
    }

    /**
     * 获取UID
     *
     * @return
     */
    public static String getUid() {
        return (String) LedimBaseSpUtils.get(UID, "", USERINFO);

    }

    /**
     * 设置LocationLatitude
     *
     * @param value
     */
    public static void setLocationLatitude(String value) {
        LedimBaseSpUtils.put(LOCATION_LATITUDE, value, USERINFO);
    }

    /**
     * 设置LocationLongitude
     *
     * @param value
     */
    public static void setLocationLongitude(String value) {
        LedimBaseSpUtils.put(LOCATION_LONGITUDE, value, USERINFO);
    }

    /**
     * 设置IsFirstShowDialog
     *
     * @param value
     */
    public static void setIsFirstShowDialog(boolean value) {
        LedimBaseSpUtils.put(IS_FIRST_SHOW_DIALOG + getUid(), value, USERINFO);
    }

    /**
     * 获取IsFirstShowDialog
     *
     * @return
     */
    public static boolean getIsFirstShowDialog() {
        return (Boolean) LedimBaseSpUtils.get(IS_FIRST_SHOW_DIALOG + getUid(), true, USERINFO);

    }


    /**
     * 设置homelocaldata
     *
     * @param value
     */
    public static void setHomeLocalData(String value) {
        LedimBaseSpUtils.put(HOME_LOCAL_DATA, value, USERINFO);
    }

    /**
     * 获取homelocaldata
     *
     * @return
     */
    public static String getHomeLocalData() {
        return (String) LedimBaseSpUtils.get(HOME_LOCAL_DATA, null, USERINFO);

    }

    /**
     * 设置user
     *
     * @param value
     */
    public static void setUser(String value) {
        LedimBaseSpUtils.put(USER, value, USERINFO);
    }

    /**
     * 获取user
     *
     * @return
     */
    public static String getUser() {
        return (String) LedimBaseSpUtils.get(USER, "", USERINFO);

    }

    /**
     * 设置letvid
     *
     * @param value
     */
    public static void setLetvId(String value) {
        LedimBaseSpUtils.put(LETVID, value, USERINFO);
    }

    /**
     * 获取letvid
     *
     * @return
     */
    public static String getLetvId() {
        return (String) LedimBaseSpUtils.get(LETVID, "0", USERINFO);

    }

    /**
     * 判断用户是否登录
     *
     * @return
     */
    public static boolean isLogin() {
        return (Boolean) LedimBaseSpUtils.get(IS_LOGIN, false, USERINFO);
    }

    /**
     * 设置登录
     *
     * @param isLogin
     */
    public static void setLogin(boolean isLogin) {
        LedimBaseSpUtils.put(IS_LOGIN, isLogin, USERINFO);
    }

    /**
     * 设置token
     *
     * @param value
     */
    public static void setToken(String value) {
        LedimBaseSpUtils.put(TOKEN, value, USERINFO);
    }

    /**
     * 获取UID
     *
     * @return
     */
    public static String getToken() {
        return (String) LedimBaseSpUtils.get(TOKEN, "0", USERINFO);

    }

    /**
     * @return 测试环境
     */
    public static boolean getDebugMark() {
        return (Boolean) LedimBaseSpUtils.get(SERVER_DEBUG_MARK, CommonDefind.DEBUG_MARK, USERINFO);
    }

    /**
     * @return 获取是否是测试环境
     */
    public static void setDebugMark(boolean isDebug) {
        LedimBaseSpUtils.put(SERVER_DEBUG_MARK, isDebug, USERINFO);
    }

    /**
     * @return 获取push消息数目
     */
    public static int getPushMgsCount() {
        return (Integer) LedimBaseSpUtils.get(PUSH_MSG_COUNT, 0, USERINFO);
    }

    /**
     * @return 设置push消息
     */
    public static void setPushMgsCount(int count) {
        LedimBaseSpUtils.put(PUSH_MSG_COUNT, count, USERINFO);
    }

    /**
     * @return 获取push消息的id
     */
    public static int getPushMsgId() {
        int count = (Integer) LedimBaseSpUtils.get(PUSH_MSG_ID, 1144, USERINFO);
        LedimBaseSpUtils.put(PUSH_MSG_ID, count + 1, USERINFO);
        return count;

    }

    /**
     * @return 设置DeviceId
     */
    public static void setDeviceId(String deviceId) {
        LedimBaseSpUtils.put(DEVICE_ID, deviceId, USERINFO);
    }

    /**
     * @return 获取DeviceId
     */
    public static String getDeviceId() {
        return (String) LedimBaseSpUtils.get(DEVICE_ID, "", USERINFO);

    }
    /**
     * 添加操作
     *
     * @param key
     * @param value
     */
    public static void put(String key, Object value) {

        LedimBaseSpUtils.put(key, value, USERINFO);
    }

    /**
     * 获取操作
     *
     * @param key
     * @param defaultValue
     */
    public static Object get(String key, Object defaultValue) {
        LedimBaseSpUtils.get(key, defaultValue, USERINFO);
        return key;
    }

    /**
     * 删除操作
     *
     * @param key
     */
    public static void remove(String key) {
        LedimBaseSpUtils.remove(key, USERINFO);
    }

    /**
     * 清楚所有的数据
     */
    public static void clearAllDatas() {
        LedimBaseSpUtils.clear(USERINFO);
    }

    /**
     * 判断是否包含某个key
     *
     * @param key
     * @return
     */
    public static boolean contains(String key) {
        return LedimBaseSpUtils.contains(key, USERINFO);
    }

}
